package com.yunhe.control;

import java.io.IOException;
import java.util.List;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.yunhe.bean.ShopUser;

/**
 * Servlet implementation class checkUser
 */
@WebServlet("/qian/checkUser.do")
public class checkUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public checkUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username=request.getParameter("username");
	
		String userpass=request.getParameter("password");
	
		String co=request.getParameter("jilu");
		/*System.out.println(userpass);
		System.out.println(username);
		System.out.println(co);*/
		if(co!=null){
			String login=username+","+userpass;
			Cookie c = new Cookie("login", login);
			c.setMaxAge(60*5);
			response.addCookie(c);			
			}
		ShopUser shopUser = new ShopUser();
		ShopUser shopUserc=null;
		shopUser.setUname(username);
		shopUser.setUpass(userpass);
		int a=0;

		List<ShopUser> checklogin = new com.yunhe.service.checkUser().checklogin(shopUser);
		
		if(checklogin.size()>0){

			for (ShopUser shopUser2 : checklogin) {
			shopUserc=shopUser2;
			a=shopUser2.getUid();
		}
		HttpSession session  = request.getSession();		
		session.setAttribute("sessionuser", shopUserc);
		session.setAttribute("userid",a);
		response.sendRedirect("IndexContorlo.do");
		/*request.getRequestDispatcher("succLogin.jsp").forward(request, response);*/
		}else{
			response.sendRedirect("login.jsp");
		}
	}

}
